<template>
  <!--弹出窗-->
  <modal ref="modal_1"
         :title="title"
         :isCloseConfirm="this.editable"
         :fullscreen="this.fullscreen"
         top="3%"
         width="80%"
         :close-on-click-modal="true"
         @modalOpened="opened"
         @modalClose="closed">

    <avue-form :option="option" ref="form" v-model="form" @submit="onSubmit" >
      <template #customerNo v-if="this.editable">
        <el-autocomplete
                style="width: 100%;"
                v-model="form.customerNo"
                :fetch-suggestions="queryCustomerNo"
                placeholder="请输入客户账号"
                :trigger-on-focus="false"
                @select="selectCustomerNo"
                :fit-input-width="true"
                :disabled="!!this.form.id || hasItem"
        ></el-autocomplete>
      </template>
      <template #customerName v-if="this.editable">
        <el-input v-model="form.customerName" readonly placeholder="请选择客户名称" @click="selectCustomerName" :disabled="!!this.form.id || hasItem"/>
      </template>
      <template #factoryName v-if="this.editable">
        <el-input v-model="form.factoryName" readonly placeholder="请选择工厂信息" @click="selectFactory"/>
      </template>
      <template #companyName v-if="this.editable">
        <el-input v-model="form.companyName" readonly placeholder="请选择银行信息" @click="selectBankInfo" :disabled="!!this.form.id || hasItem"/>
      </template>
      <template #serviceName v-if="this.editable">
        <el-input v-model="form.serviceName" readonly placeholder="请选择业务人员" @click="selectServiceName"/>
      </template>

      <template #version v-if="this.editable">
        <div style="display: flex;flex-direction: start;">
        <el-input v-model="form.version" disabled />
          <!--<el-button type="default" @click="showLog" v-if="this.form.id">修正查询-->
          <!--</el-button>-->
          <el-tooltip content="修正查询" placement="top"  v-if="this.form.id">
            <el-button
                    icon="Search"
                    plain
                    @click="() => showLog()"
            >
            </el-button>
          </el-tooltip>
        </div>
      </template>
      <!--<template #serviceName v-if="this.editable">-->
        <!--<el-input v-model="form.serviceName" readonly placeholder="请选择业务人员" @click="selectServiceName" :disabled="!!this.form.id"/>-->
      <!--</template>-->
      <template #orderItem>
        <order-item ref="orderItem" @disabledCommit="disabledCommit" @disabledFiled="disabledFiled"></order-item>
      </template>
    </avue-form>
    <!--底部按钮块, 默认只有"取消"按钮-->
    <template #footerButton>
      <el-button type="warning" v-if="!editable"
                 :disabled="btnLoading" @click="this.box = true">订单报表
      </el-button>
      <el-button type="primary" v-if="(permission.order_add || permission.order_edit) && editable"
                 :disabled="btnLoading" @click="this.$refs.form.submit()">确认订单
      </el-button>
      <el-button @click="$refs.modal_1.handleClose()">关闭</el-button>
    </template>
    <select-customer  ref="selectCustomer"  @success="setCustomerNo"/>
    <select-service  ref="selectService"  @success="setService"/>
    <select-factory  ref="selectFactory"  @success="setFactory"/>
    <select-bank  ref="selectBank"  @success="setBank"/>
    <order-log ref="orderLog"/>
    <el-dialog title="订单预览" append-to-body v-model="box" width="30%" @close="previewClose">
      <el-form-item label="语言">
        <el-radio-group v-model="isEnglish" class="list">

          <el-radio label="1" >中文</el-radio>
          <el-radio label="2" >英文</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="价格">
        <el-radio-group v-model="hiddenPrice" class="list">

          <el-radio label="1" >显示价格</el-radio>
          <el-radio label="2" >不显示价格</el-radio>
        </el-radio-group>
      </el-form-item>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="this.box = false">取 消</el-button>
          <el-button type="primary" @click="orderReport">预 览</el-button>
        </span>
      </template>
    </el-dialog>
  </modal>
</template>

<script>
    import { getList, getDetail, add, update, remove,orderReport } from "@/api/anwise/order/order";
    import {remoteList} from '@/api/anwise/customer/customer';
    import { mapGetters } from "vuex";
    import { getDeptTree } from '@/api/system/dept';
    import website from '@/config/website';
    import {Pattern} from "@/utils/validate.js";

    import selectCustomer from './select_customer.vue';
    import selectService from './select_service.vue';
    import selectFactory from './select_factory.vue';
    import selectBank from './select_bank.vue';
    import orderItem from './order_item.vue';
    import orderLog from './order_log.vue';

    export default {
        components: {
            selectCustomer,
            selectService,
            selectFactory,
            selectBank,
            orderItem,
            orderLog
        },
        data() {
            return {
              hasItem:false,
                isEnglish:'1',
                hiddenPrice:'1',
                box:false,
                emits: ["success"],
                editable: false,
                title: "订单信息",
                isCloseConfirm: false,
                fullscreen: false,
                btnLoading: false,
                customer:{
                  salesName:"",
                  remark:"",
                  salesRemark:"",
                },
                form: {},
                query: {},
                loading: true,
                option: {
                    card: true,
                    tabs: true,
                    tabsActive: 1,
                    height: 'auto',
                    calcHeight: 30,
                    labelWidth: 150,
                    menuWidth: 120,
                    submitBtn: false,
                    emptyBtn: false,
                    column: [
                        {
                            label: "订单编号",
                            prop: "idNo",
                            type: "input",
                            disabled:true,
                            display:true,
                            span:8,
                            rules: [{
                                required: false,
                                message: "请输入订单编号",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "客户账号",
                            prop: "customerNo",
                            type: "input",
                            span:8,
                            rules: [{
                                required: true,
                                message: "请选择客户账号",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "收款方",
                            prop: "companyName",
                            type: "input",
                            readonly:true,
                            span:8,
                            rules: [{
                                required: true,
                                message: "请输入收款方",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "订单日期",
                            prop: "salesDate",
                            type: "date",
                            valueFormat: 'YYYY-MM-DD',
                            format:'YYYY-MM-DD',
                            span:8,
                            disabled:true,
                        },

                        {
                            label: "客户名称",
                            prop: "customerName",
                            type: "input",
                            span:8,
                            rules: [{
                                required: true,
                                message: "请输入客户名称",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "销售货币",
                            prop: "rmb",
                            type: "input",
                           disabled:true,
                            span:8,
                        },
                        {
                            label: "付款条件",
                            prop: "paymentTerms",
                            type: "input",
                            disabled:true,
                            placeholder:' ',
                            span:8,
                        },
                        {
                            label: "联系人员",
                            prop: "contact",
                            type: "select",
                            filterable: true,
                            span:8,
                            dicData:[],
                            props: {
                                label: 'name',
                                value: 'name',
                            },
                            allowCreate:true,
                            dataType: 'string',

                        },
                        // {
                        //     label: "交货方式",
                        //     prop: "deliMeth",
                        //     type: "select",
                        //     filterable: true,
                        //     span:8,
                        //     dicUrl: '/api/blade-system/dict-biz/dictionary?code=deli_type',
                        //     props: {
                        //         label: 'dictValue',
                        //         value: 'dictKey',
                        //     },
                        //     dataType: 'string',
                        //     rules: [{
                        //         required: false,
                        //         message: "请输入交货方式",
                        //         trigger: "blur"
                        //     }],
                        // },
                      {
                        label: '贸易条款',
                        prop: 'tradeTerms',
                        type: 'select',
                        span: 8,
                        filterable:true,
                        dicUrl: '/api/blade-system/dict-biz/dictionary?code=trade_terms',
                        props: {
                          label: 'dictValue',
                          value: 'dictKey',
                        },
                        dataType: 'string',
                        rules: [
                          {
                            required: true,
                            message: '请选择贸易条款',
                            trigger: 'blur',
                          },
                        ],
                      },
                      {
                        label: '运输方式',
                        prop: 'tansportModes',
                        type: 'select',
                        span: 8,
                        filterable:true,
                        dicUrl: '/api/blade-system/dict-biz/dictionary?code=tansport_modes',
                        props: {
                          label: 'dictValue',
                          value: 'dictKey',
                        },
                        dataType: 'string',
                        rules: [
                          {
                            required: true,
                            message: '请选择运输方式',
                            trigger: 'blur',
                          },
                        ],
                      },
                        {
                            label: "客户PO",
                            prop: "custPo",
                            type: "input",
                            span:8,
                        },
                        {
                            label: "订单类型",
                            prop: "orderType",
                            type: "select",
                            filterable: true,
                            dicUrl: '/api/blade-system/dict-biz/dictionary?code=order_type',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            value:'正常',
                            dataType: 'string',
                            rules: [{
                                required: false,
                                message: "请输入订单类型",
                                trigger: "blur"
                            }],
                            span:8,
                        },
                        {
                            label: "销售方式",
                            prop: "salesType",
                            type: "select",
                            filterable: true,
                            span:8,
                            dicUrl: '/api/blade-system/dict-biz/dictionary?code=sales_type',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'string',
                            rules: [{
                                required: true,
                                message: "请输入销售方式",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "收货工厂",
                            prop: "factoryName",
                            type: "input",
                            span:8,
                            rules: [{
                                required: false,
                                message: "请输入收货工厂",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "版本",
                            prop: "version",
                            type: "input",
                            value:1,
                            disabled:true,
                            display:true,
                            span:8,
                        },
                        {
                            label: "订单状态",
                            prop: "orderStatus",
                            type: "select",
                            filterable: true,
                            dicUrl: '/api/blade-system/dict-biz/dictionary?code=order_status',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'string',
                            value:'Open',
                            rules: [{
                                required: true,
                                message: "请输入订单状态",
                                trigger: "blur"
                            }],
                            span:8,
                        },
                        {
                            label: "收货地址",
                            prop: "deliAddr",
                            type: "input",
                            span:8,
                        },
                        {
                            label: "订单来源",
                            prop: "orderSource",
                            type: "select",
                            filterable: true,
                            dicUrl: '/api/blade-system/dict-biz/dictionary?code=order_source',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'string',
                            disabled:true,
                            value:'业务创建',
                            rules: [{
                                required: false,
                                message: "请输入订单来源",
                                trigger: "blur"
                            }],
                            span:8,
                        },
                        {
                            label: "业务人员",
                            prop: "serviceName",
                            type: "input",
                            span:8,
                        },
                        {
                            label: "收货人员",
                            prop: "factoryContact",
                            type: "input",
                            span:8,
                        },
                        {
                            label: "是否发送通知",
                            prop: "enableNotice",
                            type: "select",
                            dicUrl: "/blade-system/dict-biz/dictionary?code=biz_yes_no",
                            filterable: true,
                            value:'否',
                            span:8,
                            props: {
                                label: 'dictValue',
                                value: 'dictValue',
                            },
                            dataType: 'string',
                        },
                        // {
                        //     label: "运费",
                        //     prop: "freight",
                        //     type: "number",
                        //     precision:2,
                        //     min:0,
                        //     max:999999999,
                        //     controls:false,
                        //     span:8,
                        // },
                        // {
                        //     label: "",
                        //     prop: "place",
                        //     type: "",
                        //     detail:true,
                        //     span: 8,
                        //     display:false,
                        //     // labelPosition: "top",
                        // },
                        // {
                        //     label: "业务电话",
                        //     prop: "extNo",
                        //     type: "input",
                        //     span:8,
                        // },
                        {
                            label: "箱唛",
                            prop: "salesName",
                            type: "textarea",
                            span: 12,
                            maxRows:5,
                            minRows:3
                        },
                        {
                            label: "生产备注",
                            prop: "remark",
                            type: "textarea",
                            span: 12,
                            maxRows:5,
                            minRows:3
                        },
                        {
                            label: "销售备注",
                            prop: "salesRemark",
                            type: "textarea",
                            span: 12,
                            maxRows:5,
                            minRows:3
                        },
                        {
                            label: "补货备注",
                            prop: "buhuoRemark",
                            type: "textarea",
                            span: 12,
                            minRows:3,
                            maxRows:5,
                        },
                        {
                            label: "Consignee",
                            prop: "consignee",
                            type: "input",
                            span: 12,
                        },
                      {
                        label: "内部提醒",
                        prop: "internalReminder",
                        type: "textarea",
                        maxRows:5,
                        minRows:2,
                      },
                      {
                        label: "通知方",
                        prop: "noted",
                        type: "input",
                        span: 12,
                        row:true,
                      },

                        {
                            label: "货代",
                            prop: "deliInfo",
                            type: "input",
                            span: 12,
                        },
                      {
                        label: "操作人员",
                        prop: "createUserName",
                        type: "input",
                        disabled:true,
                        span:12,
                      },
                      {
                        label: "操作时间",
                        prop: "createTime",
                        type: "input",
                        disabled:true,
                        span:12,
                      },
                        {
                            label: "统一预交日期",
                            prop: "allDeliDate",
                            type: "date",
                            valueFormat: 'YYYY-MM-DD',
                            format:'YYYY-MM-DD',
                            span:12,
                            change:	({column,value})=>{this.changeDeliDate(value)},
                        },
                    ],
                    group: [
                        {
                            icon: 'el-icon-house',
                            label: '订单项信息',
                            prop: 'group1',
                            column: [
                                {
                                    label: '',
                                    prop: 'orderItem',
                                    className: 'addPadding',
                                    span: 24,
                                    labelWidth: 0,
                                    formslot: true,
                                    display: true,
                                },
                            ],
                        },
                    ]
                },
                data: []
            };
        },
        computed: {
            ...mapGetters(["permission","userInfo"]),
            permissionList() {
                return {
                    addBtn: this.validData(this.permission.order_add, false),
                    viewBtn: this.validData(this.permission.order_view, false),
                    delBtn: this.validData(this.permission.order_delete, false),
                    editBtn: this.validData(this.permission.order_edit, false)
                };
            },
            ids() {
                let ids = [];
                this.selectionList.forEach(ele => {
                    ids.push(ele.id);
                });
                return ids.join(",");
            }
        },
        mounted() {
        },
        methods: {
          disabledFiled(hasItem) {
            this.hasItem = hasItem;
          },
            changeDeliDate(value) {
                let orderItem = this.$refs.orderItem.$refs.tableRef.getTableData().fullData;
                if (orderItem.length > 0) {
                    orderItem.forEach(item => {
                        item.deliDate = value;
                    })
                }
            },
            previewClose() {
                this.isEnglish='1';
                this.hiddenPrice='1';
            },
            orderReport() {
                orderReport(this.form.id, this.isEnglish, this.hiddenPrice).then(res => {
                    if(res.data.success) {
                        console.log(res.data)
                        const file = res.data.data;
                        // const originUrl = (file.url.replace(file.domain, `${this.res}/`));
                        const url = file.url;
                        // this.$refs.preview.open({
                        //     url: url || "",
                        //     originUrl: originUrl || ""
                        // });
                        window.open(`/plugins/pdfjs/web/viewer.html?file=`+url);
                    }
                })
            },
            showLog() {
                this.$refs.orderLog.show(this.form.id);
            },
            disabledCommit(data) {
                this.btnLoading = data;
            },
            setBank(row) {
                this.form.companyName = row.companyName;
                this.form.rmb = row.rmb;
                this.form.bankId = row.id;
                this.$refs.orderItem.bankId= row.id;
            },
            selectBankInfo() {
                if (this.form.customerNo)  {
                    this.$refs.selectBank.showSelect(this.form.customerId);
                } else {
                    this.$message({
                        type: "error",
                        message: "请先选择客户信息!"
                    });
                }
            },
            setFactory(row) {
                if (row) {
                    this.form.factoryId = row.id;
                    this.form.deliAddr = row.facAddr;
                    this.form.factoryName = row.facName;
                    this.form.consignee = row.consignee;
                    this.form.factoryContact = row.contact;
                    this.form.salesName = this.customer.salesName+(this.customer.salesName === "" ? "":"\n")+row.cartonMarkRemark;
                    this.form.remark = this.customer.remark+(this.customer.remark === "" ? "":"\n")+row.prodRemark;
                    this.form.salesRemark = this.customer.salesRemark+(this.customer.salesRemark === "" ? "":"\n")+row.salesRemark;
                }
            },
            selectFactory() {
              if (this.form.customerNo)  {
                this.$refs.selectFactory.showSelect(this.form.customerId);
              } else {
                  this.$message({
                      type: "error",
                      message: "请先选择客户信息!"
                  });
              }
            },
            setService(row) {
                console.log(row);
                if (row) {
                    this.form.serviceName = row.realName;
                    this.form.serviceId = row.id;
                    this.form.extNo = row.phone;
                }
            },
            selectServiceName() {
                this.$refs.selectService.showSelect();
            },
            queryCustomerNo(val,cb) {
              this.form.customerName = "";
                this.$refs.orderItem.customerId="";
              const column =  this.findObject(this.option.column, 'contact');
              column.dicData = [];
              this.form.contact = "";
              this.form.factoryName = "";
                const reg = Pattern.number;
                console.log(reg.test(val));
                if (!reg.test(val)) {
                    this.$message({
                        type: "error",
                        message: "客户账号只能为数字!"
                    });
                    return;
                }

                remoteList(val).then(res => {
                    if (res.data.success) {
                        let customerList = [];
                        res.data.data.forEach(item => {
                            let contactList = [];
                            if (item.contact1) {
                                contactList.push({name: item.contact1})
                            }
                            if (item.contact2) {
                                contactList.push({name: item.contact2})
                            }
                            if (item.contact3) {
                                contactList.push({name: item.contact3})
                            }
                            customerList.push({
                                value:item.custNo +" - "+item.custName,
                                customerId: item.id,
                                customerNo: item.custNo,
                                customerName: item.custName,
                                paymentTerms:item.paymentTerms,
                                tansportModes:item.tansportModes,
                                tradeTerms:item.tradeTerms,
                                contactList:contactList,
                              cartonMarkRemark:item.cartonMarkRemark,
                              prodRemark:item.prodRemark,
                              salesRemark:item.salesRemark,
                              internalReminder: item.internalReminder,
                            });
                        })
                        cb(customerList);
                    }
                })
            },
            selectCustomerNo(item) {
                console.log(item);
                this.form.customerId = item.customerId;
                this.form.customerNo = item.customerNo;
                this.form.customerName = item.customerName;
                const column =  this.findObject(this.option.column, 'contact');
                column.dicData = item.contactList;
                if (item.contactList.length > 0) {
                  this.form.contact = item.contactList[0].name;
                }
                this.form.paymentTerms = item.paymentTerms;
                this.form.tansportModes = item.tansportModes;
                this.form.tradeTerms = item.tradeTerms;
                this.form.salesName = item.cartonMarkRemark;
                this.form.remark = item.prodRemark;
                this.form.salesRemark = item.salesRemark;
              this.form.internalReminder= item.internalReminder;
                this.customer.salesName = item.cartonMarkRemark;
                this.customer.remark = item.prodRemark;
                this.customer.salesRemark = item.salesRemark;
                this.$refs.orderItem.customerId=item.customerId;
            },
            setCustomerNo(row) {
              this.form.customerName = "";
              const column =  this.findObject(this.option.column, 'contact');
              column.dicData = [];
              // this.form.contact = "";
              this.form.factoryName = "";
              if (row) {
                  this.form.customerId = row.id;
                  this.form.customerNo = row.custNo;
                  this.form.customerName = row.custName;
                  this.form.salesName = row.cartonMarkRemark;
                  this.form.remark = row.prodRemark;
                  this.form.salesRemark = row.salesRemark;
                this.form.internalReminder= row.internalReminder;
                  this.customer.salesName = row.cartonMarkRemark;
                  this.customer.remark = row.prodRemark;
                  this.customer.salesRemark = row.salesRemark;
                 const column =  this.findObject(this.option.column, 'contact');
                  column.dicData=[];
                 if (row.contact1) {
                     column.dicData.push({name:row.contact1});
                     this.form.contact = row.contact1;
                 }
                  if (row.contact2) {
                      column.dicData.push({name:row.contact2});
                  }
                  if (row.contact3) {
                      column.dicData.push({name:row.contact3});
                  }
                  this.form.paymentTerms = row.paymentTerms;
                  this.form.tansportModes = row.tansportModes;
                  this.form.tradeTerms = row.tradeTerms;
                  this.$refs.orderItem.customerId=this.form.customerId;
                  this.$refs.orderItem.editable = this.editable;
                  this.$refs.orderItem.salesDate = this.salesDate;
              }
            },
            selectCustomerName() {
              this.$refs.selectCustomer.showSelect();
            },
            async validItemEvent() {
                const $table = this.$refs.orderItem.$refs.tableRef
                let errMap = undefined;
                    await $table.validate().then((err) => {
                        console.log("err:",err)
                        errMap=err;
                    })
                  return errMap;
            },
            async onSubmit(form, done) {
                console.log("this.$refs.orderItem.$refs.tableRef",this.$refs.orderItem.$refs.tableRef.getTableData().fullData);
                const $table = this.$refs.orderItem.$refs.tableRef
                let checkOrderItem = false;
                 const errMap = await this.validItemEvent();
                  console.log(errMap);
                     if (errMap) {
                         this.$message({
                             type: 'error',
                             message: '订单项信息有误！',
                         });
                         checkOrderItem = true;
                         done();
                         return;
                     }

                console.log("checkOrderItem",checkOrderItem);
                if (!checkOrderItem) {
                    this.btnLoading = true;
                    form.isConfirm = this.editable ? 1 : 0;
                    form.addList = $table.getInsertRecords();
                    form.updateList = $table.getUpdateRecords();
                    form.deleteList = $table.getRemoveRecords();
                    form.itemList = $table.getTableData().fullData;
                    if (!form.itemList || form.itemList.length < 1) {
                        this.$message({
                            type: 'error',
                            message: '无订单项信息！',
                        });
                        this.btnLoading = false;
                        return;
                    }
                    console.log(form)
                    update(form).then(res => {
                        if (res.data.success) {
                            this.$message({
                                type: "success",
                                message: res.msg || "保存成功!"
                            });
                            setTimeout(() => {
                              this.btnLoading = false;
                              done();
                                this.$refs.modal_1.hide();
                            }, 1000)
                        } else {
                            this.$message({
                                type: "error",
                                message: res.msg || "保存失败!"
                            });
                        }
                    }).catch(err => {
                        console.log(err)
                        done();
                        this.btnLoading = false;
                    })

                }
            },
            show(option) {
                this.title = option.title;
                this.type = option.type;
                this.option.detail = this.type === "view";
                this.editable = this.type !== "view";
                this.customer = {};
                if (option.id) {
                    console.log("option.id");
                    setTimeout(() => {
                        getDetail(option.id).then(res => {
                            if (res.data.success) {
                                this.form = res.data.data;
                                this.customer.salesName =  this.form.customer.cartonMarkRemark;
                                this.customer.remark = this.form.customer.prodRemark;
                                this.customer.salesRemark = this.form.customer.salesRemark;
                                this.$refs.orderItem.setData(this.editable, this.form.idNo)
                                console.log("this.$refs.orderItem.idNo",this.$refs.orderItem.idNo);
                                this.$refs.orderItem.customerId=this.form.customerId;
                                this.$refs.orderItem.idNo=this.form.idNo;
                                this.$refs.orderItem.bankId= this.form.bankId;
                                this.$refs.orderItem.editable = this.editable;
                                this.$refs.orderItem.salesDate = this.form.salesDate;
                                // this.form.taxRate = Number(this.form.taxRate)
                                // this.findObject(this.option.column, 'idNo').display = true;
                                // this.findObject(this.option.column, 'version').display = true;

                                const column =  this.findObject(this.option.column, 'contact');
                                column.dicData=[];
                                if (res.data.data.customer.contact1) {
                                    column.dicData.push({name:res.data.data.customer.contact1});
                                }
                                if (res.data.data.customer.contact2) {
                                    column.dicData.push({name:res.data.data.customer.contact2});
                                }
                                if (res.data.data.customer.contact3) {
                                    column.dicData.push({name:res.data.data.customer.contact3});
                                }
                                console.log("column",column);
                            }
                        })
                    }, 500);
                } else {
                    this.form = {}
                    this.findObject(this.option.column, 'contact').dicData = [];
                    // this.findObject(this.option.column, 'idNo').display = false;
                    // this.findObject(this.option.column, 'version').display = false;
                    console.log(this.userInfo)
                    if(this.userInfo.role_id.includes("1719727370609577986")){
                        console.log("this.userInfo",this.userInfo);
                      this.form.serviceName = this.userInfo.real_name;
                      this.form.serviceId = this.userInfo.user_id;
                      this.form.extNo = this.userInfo.phone;
                    }
                    this.hasItem=false;
                }

                this.$refs.modal_1.show();
            },
            rowDel(row) {
                this.$confirm("确定将选择数据删除?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        return remove(row.id);
                    })
                    .then(() => {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    });
            },
            handleDelete() {
                if (this.selectionList.length === 0) {
                    this.$message.warning("请选择至少一条数据");
                    return;
                }
                this.$confirm("确定将选择数据删除?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        return remove(this.ids);
                    })
                    .then(() => {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                        this.$refs.crud.toggleSelection();
                    });
            },
            beforeOpen(done, type) {
                if (["edit", "view"].includes(type)) {
                    getDetail(this.form.id).then(res => {
                        this.form = res.data.data;
                    });
                }
                done();
            },
            opened() {
                console.log("opened")
            },
            closed() {

                this.$emit("success");
            }
        }
    };
</script>

<style>
  /*.addPadding {*/
    /*padding: 20px !important;*/
  /*}*/
</style>
